package springmvc_demo.config;


import org.aopalliance.intercept.Interceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry){
        registry.addViewController("/text1").setViewName("/text1"); // 页面跳转
        registry.addViewController("/text111").setViewName("/text1");
        registry.addViewController("/text2").setViewName("/text2");
    }
    @Autowired
    private MyInterceptor myInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry){ // 拦截器
        registry.addInterceptor(myInterceptor)
                .addPathPatterns("/**").excludePathPatterns("/login");
    }
}
